use turk_experiment_2012.dta, clear

* Gen indicators for hispanic and born again
tab var84, gen(hispanic)
ren hispanic1 hispanic

tab var85, gen(bornagain)
ren bornagain1 bornagain

* Generate indicator for party of candidate
encode var151, gen(cand_party)
label define party 1 "Dem" 2 "Rep"
label values cand_party party

* Generate variable indicating which condition non-Latino and non-Born again respondents received
* Note that string variables identify conditions incorrectly

gen condition_out=1 if var147=="Branch C - Latino"
replace condition_out=2 if var147=="Branch A - Control" 
replace condition_out=3 if var147=="Branch B - Christian"

label define cond 1 "Control" 2 "Christians" 3 "Latinos"
label values condition_out cond

* Generate variable indicating which condition Latino respondents received

gen condition_latinos=1 if var150=="Control" | var150=="Branch A"
replace condition_latinos=2 if var150=="New Branch" | var150=="Latino"

label define cond2 1 "Control" 2 "Latinos" 
label values condition_latinos cond2

* Generate variable indicating which condition Born Again respondents received

gen condition_ba=1 if var148=="Control" | var148=="Branch A"
replace condition_ba=2 if var148=="New Branch" | var148=="Christian"

label values condition_ba cond

* Generate variable for how respondents rated Williams' ideology

gen williams_ideology=var119-10374
recode williams_ideology 8=.

* Generate variable indicating support for williams

recode var88 9=1 8=2 7=3 6=4 5=5 4=6 3=7 2=8 1=9, gen(support)

* Generate variables capturing how much R thinks Williams cares about groups

recode var167 10465=4 10466=3 10471=2 10472=1 10473=., gen(cares_mc)
recode var169 10465=4 10466=3 10471=2 10472=1 10473=., gen(cares_lat)
recode var170 10465=4 10466=3 10471=2 10472=1 10473=., gen(cares_ba)

label define cares 1 "Does not care at all" 2 "Does not care much" 3 "Cares somewhat" 4 "Cares very much"
label values cares_mc cares
label values cares_lat cares
label values cares_ba cares

* Generate an indicator which equals 1 if R got born again appeal, 0 if got general appeal 
* (Missing if received Latino appeal)
gen ba_appeal=1 if condition_out==2 | condition_ba==2
replace ba_appeal=0 if condition_out==1 | condition_ba==1 | condition_lat==1

* Generate an indicator which equals 1 if R got latino appeal, 0 if got general appeal 
* (Missing if received born again appeal)
gen lat_appeal=1 if condition_out==3 | condition_lat==2
replace lat_appeal=0 if condition_out==1 | condition_lat==1 | condition_ba==1


*** Generate Estimates for Figure 1 in Appendix ***

* IN GROUP EFFECTS
* Democratic candidate
reg support lat_appeal if cand_party==1 & hispanic==1
reg support ba_appeal if cand_party==1 & bornagain==1

* Republican candidate
reg support lat_appeal if cand_party==2 & hispanic==1
reg support ba_appeal if cand_party==2 & bornagain==1

* OUT GROUP EFFECTS
* Democratic candidate
reg support ba_appeal if cand_party==1 & bornagain==0
reg support lat_appeal if cand_party==1 & hispanic==0

* Republican candidate
reg support ba_appeal if cand_party==2 & bornagain==0
reg support lat_appeal if cand_party==2 & hispanic==0



recode cares_mc-cares_ba (4=1) (3=1) (2=0) (1=0), gen(cares_mc2 cares_lat2 cares_ba2)

* Analysis reported in footnote X
proportion cares_ba2, over(condition_out)
proportion cares_ba2, over(condition_ba)

proportion cares_lat2, over(condition_out)
proportion cares_lat2, over(condition_lat)

proportion cares_lat2 if condition_lat==1 | condition_out==1, over(var84)
proportion cares_ba2 if condition_ba==1 | condition_out==1, over(var85)

